package luzhin;

import java.util.*;

/**
 * Pool of unused boards.
 * Make sure you've run initPool() before using it.
 *
 * TODO make non-static
 * @author lacungus
 *
 */

public class BoardPool {
	
	private static LinkedList<Board> boards;	
	private static int maxBoardsInPool = 0;
	private static int boardsAsked = 0;
	private static int boardsReused = 0;
	
	public static void initPool() {
		boards = new LinkedList<Board>();
	}

    static {
        initPool();
    }
	
	/**
	 * Adds board to pool.
	 * Be sure you don't need this board.
	 */
	public static void addBoard(Board board) {
		boards.add(board);
		maxBoardsInPool = Math.max(maxBoardsInPool, boards.size());
	}
	
	/**
	 * 
	 * @return some board to be used.
	 */
	public static Board getBoard() {
		boardsAsked++;
		if (boards.isEmpty()) 
			return new Board();			
		else {
			boardsReused++;
			return boards.pollFirst();
		}
	}
	
	public static int getBoardsAsked() {
		return boardsAsked;
	}
	
	public static int getBoardsReused() {
		return boardsReused;
	}
	
	public static int getMaxBoardsInPool() {
		return maxBoardsInPool;
	}
}
